package com.hot100.mid;

/**
 * @author zhengTao
 * @version 1.0
 * @description: 跳跃游戏
 * @date 2022/8/7 17:52
 */
public class Demo18 {

    public static void main(String[] args) {
        int[] nums={0,1};
        System.out.println(canJump1(nums));
    }


    //理解题意错误
    public static boolean canJump(int[] nums) {
           int index =0;
           while (index<=nums.length-1){
               if(index== nums.length-1){
                   return true;
               }
               if(nums[index]==0){
                   return false;
               }
               index+=nums[index];
           }
           return true;
    }

    public static boolean canJump1(int[] nums) {

        int index =nums.length;
        if(index<=1){
            return true;
        }
        int temp=index-1;
        for (int i = index-2; i>=0 ; i--) {
           if(i+nums[i]>=temp){
               temp=i;
           }
        }
        return temp==0;
    }
}
